<template>
	<!-- 用户手动完善信息 -->
	<view class="container">
		<form @submit="handleSubmit">
			<view class="item mt-30">
				<button open-type="chooseAvatar" @chooseavatar="onChooseAvatar"
					style="background-color: #fff; padding: 0;">
					<view class="profile-photo dis-center h-80">
						<text style="font-size: 30rpx;">头像</text>
						<view class="dis-ali-center">
							<image class="avatar-image mr-20"
								:src="avatar_url ? avatar_url : 'https://thirdwx.qlogo.cn/mmopen/vi_32/POgEwh4mIHO4nibH0KlMECNjjGxQUq24ZEaGT4poC6icRiccVGKSyXwibcPq4BWmiaIGuG1icwxaQX6grC9VemZoJ8rg/132'"
								mode="aspectFill" />
							<u-icon name="arrow-right" color="#8c8b8b" size="20" />
						</view>
					</view>
				</button>
			</view>

			<view class="item mt-4">
				<view class="dis-ali-center h-80" @click="getUserNickName">
					<text style="font-size: 30rpx; flex: 1;">昵称</text>

					<view style="color: #8c8b8b; flex: 4;">
						<input style="text-align: right;" type="nickname" name="nickName" :value="nick_name" placeholder="请输入昵称" />
					</view>
				</view>
			</view>
			
			<view class="submit">
			  <button class="submit-btn" form-type="submit">确定</button>
			</view>
		</form>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				// 昵称
				nick_name: '',
				// 头像
				avatar_url: ''
			}
		},
		methods: {
			// 获取用户昵称
			getUserNickName() {},

			// 用户选择头像
			onChooseAvatar(e) {
				const {
					avatarUrl
				} = e.detail
				console.log('用户选择头像==>', e);
				this.avatar_url = avatarUrl
			},

			// 确定
			handleSubmit(e) {
				const { nickName } = e.detail.value
				const info = {
					nick_name: nickName,
					avatar_url: this.avatar_url
				}
				uni.setStorageSync('my_profile', info)
			},

			onNavigateBack(delta = 1) {
				// 获取页面实例,返回一个存放页面的数组,当前页在数组第一个元素
				const pages = getCurrentPages()
				// 由其他页面跳转到当前页面
				if (pages.length > 1) {
					uni.navigateBack({
						delta: Number(delta || 1)
					})
				} else {
					// 无其他页面跳转到当前页面，直接跳转到我的页面
					this.$navTo('pages/user/index')
				}
			},

		},
	}
</script>

<style>
	page {
		background-color: rgb(247, 247, 247);
	}
</style>

<style lang="scss" scoped>
	.dis-center {
		display: flex;
		align-items: center;
		justify-content: space-between;
	}

	.dis-ali-center {
		display: flex;
		align-items: center;
	}

	.h-80 {
		height: 80rpx;
	}

	.item {
		background-color: #fff;
		padding: 20rpx 40rpx;
	}

	.avatar-image {
		width: 80rpx;
		height: 80rpx;
		border-radius: 50%;
	}

	.submit {
		display: flex;
		justify-content: center;
		margin-top: 50rpx;

		.submit-btn {
			width: 80%;
			height: 86rpx;
			background: linear-gradient(to right, #ecb53c, #ff9211);
			color: #fff;
			margin: 0 auto;
			font-size: 28rpx;
			border-radius: 50rpx;
			border: 1px solid #dcdcdc;
			padding: 16rpx 0;
			text-align: center;
			display: flex;
			justify-content: center;
			align-items: center;
		}
	}
</style>
